<?php

namespace app\api\middleware;

use think\facade\Log;
use think\Request;
use app\api\service\common\AuthCheckService;

class AuthCheck
{
    public function __construct(
        protected AuthCheckService $authCheckService
    )
    {
    }

    public function handle(Request $request, \Closure $next)
    {
        // 记录日志
        if(app()->isDebug()){
            $path = request()->url();
            $params = json_encode(request()->param());
            trace("\r\n" . $path . $params,'-------------------------Start---------------------------');
        }

        // 分别检查短信验证码、JWT、图形验证码
        $url = $request->pathinfo();
        $this->authCheckService->check($request,$url);

        return $next($request);
    }
}